package cn.how2go.net.server;

import cn.how2go.net.server.component.RabbitmqQueue;
import cn.how2go.net.server.service.SenderService;
import cn.how2go.net.server.thread.ByteLogRunnable;
import cn.how2go.net.server.thread.CtxMessageRunnable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class ServerService {
    private static Logger logger = LoggerFactory.getLogger(ServerService.class);

    @Autowired
    private NetServer netServer;

    @Autowired
    private SenderService senderService;

    @Autowired
    private RabbitmqQueue rabbitmqQueue;

    @PostConstruct
    public void start(){
        // 启动服务器
        if(netServer!=null) {
            try {
                netServer.startd();
            }catch (Exception e){
                logger.error("服务器启动失败");
            }
        }

        ByteLogRunnable byteLogRunnable = new ByteLogRunnable();
        Thread byteLogThread = new Thread(byteLogRunnable);
        byteLogThread.start();

        CtxMessageRunnable ctxMessageRunnable = new CtxMessageRunnable(senderService);
        Thread ctxMessageThread = new Thread(ctxMessageRunnable);
        ctxMessageThread.start();

    }
}
